//
// Created by francklinson on 2021/5/21.
//
#include <vector>
#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

class Solution {
public:
    double maxAverageRatio(vector<vector<int>> &classes, int extraStudents) {
        priority_queue<tuple<double, int, int> > pq;
        auto diff = [](int a, int b) -> double {
            return (double) (a + 1) / (b + 1) - (double) a / b;
        };
        double ans = 0;
        for (auto &c:classes) {
            int x = c[0], y = c[1];
            ans += (double) x / y;
            pq.emplace(diff(x, y), x, y);
        }
        for (int i = 0; i < extraStudents; ++i) {
            auto d = get<0>(pq.top());
            auto x = get<1>(pq.top());
            auto y = get<2>(pq.top());
            pq.pop();
            ans += d;
            pq.emplace(diff(x + 1, y + 1), x + 1, y + 1);
        }
        return ans / classes.size();
    }
};

int main() {
    vector<vector<int>> classes{{1, 2},
                                {3, 5},
                                {2, 2}};
    Solution sol;
    cout << sol.maxAverageRatio(classes, 2) << endl;
    return 0;
}